package com.bems.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bems.jdbc.common.DBManager;
import com.bems.pojo.Supply;
import com.bems.service.SupplyService;
import com.bems.util.PageUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

import cn.org.ape.BaseAction;

public class SupplyAction extends BaseAction 
{
			SupplyService supplyService = new SupplyService();
			private int limit;
			private int page;
			private Supply supply;
			private int id;
			
			
			
			public void list() {
				
				JsonObject jsonObject = new JsonObject();	
				PageUtil pageutil=supplyService.list(page, limit);
				jsonObject.addProperty("totalCount", pageutil.getTotalpage());
				Gson gson = new Gson();
				
				jsonObject.add("resultList", gson.toJsonTree(pageutil.getList()));
				DBManager.closeConnection();
				printJson(jsonObject.toString());
			}
			public void status() {
				
				
				Gson gson = new Gson();
				List<Supply> list = supplyService.list();
				DBManager.closeConnection();
				printJson(gson.toJson(list).toString());
				
			}
			
			public void add() 
			{
				supply.setStatus(1);
				supplyService.add(supply);
				String json="{success:true}";
				DBManager.closeConnection();
				printJson(json);
			}
			
			
			public void update() 
			{
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("name",supply.getName());
				map.put("adderss",supply.getAdderss());
				map.put("linkman",supply.getLinkman());
				map.put("contact",supply.getContact());
				map.put("status",request.getParameter("supply.status")!=null?supply.getStatus():0);
				map.put("note",supply.getNote());
				new Supply().update(map, Long.parseLong(id+""));
				String json="{success:true}";
				
				DBManager.closeConnection();
				printJson(json);
			}
			
			public int getPage() {
				return page;
			}


			public void setPage(int page) {
				this.page = page;
			}


			public void setLimit(int limit) {
				this.limit = limit;
			}
			public int getLimit() {
				return limit;
			}
			public Supply getSupply() {
				return supply;
			}
			public void setSupply(Supply supply) {
				this.supply = supply;
			}
			public int getId() {
				return id;
			}
			public void setId(int id) {
				this.id = id;
			}
}
